*you will need to download DownWilson_Ftest from: http://eup.sagepub.com/content/11/1/61.short. You will need to log in via your institutional
*journal access to download the supplemantary material. After you downloaded the files, you will need to copy paste the DownWilson_Ftest ado into
*your stata ado directory (http://www.stata.com/support/faqs/programming/personal-ado-directory/).

*Then you will need to open the dataset: 03_BischofFinkSPSR2015.dta
use "03_BischofFinkSPSR2015.dta"

drop if year<=1980 | year==2009
drop if hmccode==660
*Lebanon 
*Kuwait (1984 1992), Oman (1992) the repression index has missing values. We interpolate these three values in order to not loose the whole time series.
*Lebanon needs to be exlcuded due to too many missings.   
by hmccode: ipolate rep year, gen(inth_repression_equal) 

*For Morocco one year (1988) does not have a value for conflictindex. Since we need balanced panels this would essentially mean we need to exclude Morocco due
*to one value. Instead of that we use linear interpolation to fill this one gap:
by hmccode: ipolate BFconflictindex year, gen(intBFconflictindex) 

*Test units root:
*Dickey fuller Test for stationarity: 
*The null hypothesis of this test is that all panels contain a unit root. Given your results we reject this hypothesis. 
*If you look at your tests P, Z, L* and Pm, you get a value for these test statistics (77.8047, -7.2246, and so on) and in the next column
* you see the p-value. Since they are all smaller than 0.01, you can reject the null hypothesis at the 1% level of statistical significance. 
*This means there are no unit roots in your panels under the given test conditions (included panel mean and time trend).

xtunitroot llc inth_repression_equal
xtunitroot llc intBFconflictindex

*-> We reject the null hypotheses that all panels contain a unit root, since p-values <=0.01. 

*Now we need to know how much T and n is left:
xtdes
*Still n=18 and T=28, so still a fairly large T per n. 

*Now we can run the granger causality stuff: 
*Question is how many lags should be included. As it appears scholars tend to use as many lags as there are significant when running regressions of variables
*on themselves. The issue is that in our case they are always significant. I would suggest we just report as many lags as there are significant for the Granger
*test: 

********************************************************
********************************************************
*************Repression -> Conflict*********************
********************************************************
*repression Granger causes conflict
*LAG=1
gen v1 = intBFconflictindex
label variable v1 "conflict"
gen v2 = inth_repression_equal
label variable v2 "repression"
gen p = 1
gen N = 18
gen T = 28
gen panel = hmccode
gen alpha = 0.001

DownWilson_Ftest v1 v2 p N T panel alpha

*p = 0.01 significant
drop  v1- f3iv2lag696

*LAG=2
*repression Granger causes conflict
gen v1 = intBFconflictindex
label variable v1 "conflict"
gen v2 = inth_repression_equal
label variable v2 "repression"
gen p = 2
gen N = 18
gen T = 28
gen panel = hmccode
gen alpha = 0.05

DownWilson_Ftest v1 v2 p N T panel alpha

*p = 0.10 significant
 drop  v1- iv2lag698

*LAG=3
*repression Granger causes conflict
*gen v1 = intBFconflictindex
*label variable v1 "conflict"
*gen v2 = inth_repression_equal
*label variable v2 "repression"
*gen p = 3
*gen N = 18
*gen T = 28
*gen panel = hmccode
*gen alpha = 0.05

*DownWilson_Ftest v1 v2 p N T panel alpha

*insignificant on conventional levels
*drop  v1-iv2lag698

********************************************************
********************************************************
*************Conflict -> Repression*********************
********************************************************
*conflict Granger causes repression

*LAG=1
gen v2 = intBFconflictindex
label variable v2 "conflict"
gen v1 = inth_repression_equal
label variable v1 "repression"
gen p = 1
gen N = 18
gen T = 28
gen panel = hmccode
gen alpha = 0.05

DownWilson_Ftest v1 v2 p N T panel alpha

*p = 0.05 significant
 drop  v2- iv2lag698
 
*LAG=2
*conflict Granger causes repression
*gen v2 = intBFconflictindex
*label variable v2 "conflict"
*gen v1 = inth_repression_equal
*label variable v1 "repression"
*gen p = 2
*gen N = 18
*gen T = 28
*gen panel = hmccode
*gen alpha = 0.05

*DownWilson_Ftest v1 v2 p N T panel alpha

*insignificant on conventional levels 
* drop  v2- iv2lag698
